<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
  import echarts from 'echarts'
  require('echarts/theme/macarons') // echarts theme
  import resize from './mixins/resize'

  export default {
    mixins: [resize],
    props: {
      className: {
        type: String,
        default: 'chart'
      },
      width: {
        type: String,
        default: '100%'
      },
      height: {
        type: String,
        default: '300px'
      }
    },
    data() {
      return {
        chart: null
      }
    },
    mounted() {
      this.$nextTick(() => {
        this.initChart()
      })
    },
    beforeDestroy() {
      if (!this.chart) {
        return
      }
      this.chart.dispose()
      this.chart = null
    },
    methods: {
      initChart() {
        this.chart = echarts.init(this.$el, 'macarons')

        this.chart.setOption({
          title: {
            text: '华为&阿帕智慧物流云',
            left: 20,
            top: 20,
            textStyle: {
              color: '#666666',
              fontSize: '14'
            }
          },
          tooltip: {
            trigger: 'item',
            formatter: '{a} <br/>{b} : {c} ({d}%)'
          },
          series: [{
            name: '华为&阿帕智慧物流云',
            type: 'pie',
            radius: ['50%', '60%'],
            avoidLabelOverlap: false,
            center: ['50%', '50%'],
            data: [{
                value: 320,
                name: 'SCM'
              },
              {
                value: 240,
                name: 'WMS'
              },
              {
                value: 149,
                name: 'TMS'
              },
              {
                value: 100,
                name: 'OMS'
              },
            ],
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }]
        })
      }
    }
  }
</script>
<style scoped="scoped" lang="scss">
  .chart {
    background-color: #FFFFFF;
  }
</style>
